
/**
 * Project Name:cats-core
 * File Name:Role.java
 * Package Name:com.catsic.core.entity
 * Date:2014年2月26日下午4:24:18
 * Copyright (c) 2014, oa.catsic.com All Rights Reserved.
 */
 
package com.catsic.core.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Where;

import com.catsic.base.BaseEntity;
import com.catsic.base.status.Status;


/**
 * ClassName: Role
 * Description: 角色实体类
 * date: 2014年2月26日 下午4:24:18
 * author: yangyd
 */
@Entity
@Table(name="S_ROLE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Role extends BaseEntity implements Serializable{

	private static final long serialVersionUID = 2556633809952749782L;
	
	/**
	 * name:角色名称
	 */
	@Column(name="NAME",nullable=false)
	private String name;
	
	/**
	 * status:状态
	 */
	@Enumerated(EnumType.STRING)
	@Column(name="STATUS")
	private Status status = Status.有效;
	
	/**
	 * organ:所属机构
	 */
	@ManyToOne(fetch = FetchType.LAZY,optional = false)
	@JoinColumn(name="OID",referencedColumnName = "ID")
	private Organ organ;
	
	/**
	 * users:用户
	 * 维护端是roles类，role删除的，会删除中间表
	 */
	@ManyToMany(fetch = FetchType.LAZY,mappedBy="roles")
	private List<User> users;
	
	/**
	 * menus:菜单
	 */
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "S_ROLE_MENU",   
    joinColumns ={@JoinColumn(name = "ROLEID", referencedColumnName = "ID") },   
    inverseJoinColumns = { @JoinColumn(name = "MENUID", referencedColumnName = "ID")})
	@OrderBy("sort ASC")
	@Where(clause = "status='有效'")
	@Cache (usage = CacheConcurrencyStrategy.READ_WRITE)  
	private List<Menu> menus;
	
	/**
	 * resources:资源
	 */
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "S_ROLE_RESOURCE",   
    joinColumns ={@JoinColumn(name = "ROLEID", referencedColumnName = "ID") },   
    inverseJoinColumns = { @JoinColumn(name = "RESOURCEID", referencedColumnName = "ID")})
	@OrderBy("code ASC")
	@Where(clause = "status='有效'")
	@Cache (usage = CacheConcurrencyStrategy.READ_WRITE)  
	private List<Resource> resources;
	
	/**
	 * organs:授权机构
	 */
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "S_ROLE_ORGAN",   
    joinColumns ={@JoinColumn(name = "ROLEID", referencedColumnName = "ID") },   
    inverseJoinColumns = { @JoinColumn(name = "ORGANID", referencedColumnName = "ID")})
	@Where(clause = "status='有效'")
	@Cache (usage = CacheConcurrencyStrategy.READ_WRITE)
	private List<Organ> organs;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Organ getOrgan() {
		return organ;
	}

	public void setOrgan(Organ organ) {
		this.organ = organ;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public List<Menu> getMenus() {
		return menus;
	}

	public void setMenus(List<Menu> menus) {
		this.menus = menus;
	}

	public List<Resource> getResources() {
		return resources;
	}

	public void setResources(List<Resource> resources) {
		this.resources = resources;
	}

	public List<Organ> getOrgans() {
		return organs;
	}

	public void setOrgans(List<Organ> organs) {
		this.organs = organs;
	}
}
